package router

import (
	systemController "gitee.com/wangshh_123/cross-pay-go/src/controller/system"
	"gitee.com/wangshh_123/cross-pay-go/src/middleware"
	"gitee.com/wangshh_123/cross-pay-go/src/platform/providers/photonpay"

	"github.com/gin-gonic/gin"
)

// SetupAccountRouter 设置账号管理路由
func SetupAccountRouter(api *gin.RouterGroup, photonPayClient *photonpay.PhotonPayClient) {
	accountController := systemController.NewAccountController(photonPayClient)

	// 主账号路由组
	masterGroup := api.Group("/master-accounts")
	masterGroup.Use(middleware.AuthMiddleware()) // 添加认证中间件
	{
		masterGroup.POST("", accountController.CreateMasterAccount)                             // 创建主账号
		masterGroup.GET("/info", accountController.GetMasterAccount)                            // 获取主账号信息（避免与 /:master_id/funds 冲突）
		masterGroup.GET("/sub-accounts", accountController.GetSubAccountsByMasterID)            // 获取主账号下的所有子账号
		masterGroup.GET("/sub-accounts/search", accountController.GetSubAccountsWithConditions) // 根据条件查询子账号
		masterGroup.PUT("/", accountController.UpdateMasterAccount)                             // 更新主账号信息
		masterGroup.POST("/allocate-balance", accountController.AllocateBalance)                // 主账号划拨余额给子账号
		masterGroup.GET("/funds", accountController.GetMasterSubAccountFunds)                   // 查询主账号资金划拨明细
	}

	// 子账号路由组
	subGroup := api.Group("/sub-accounts")
	subGroup.Use(middleware.AuthMiddleware()) // 添加认证中间件
	{
		subGroup.POST("/consume", accountController.SubAccountConsume)                      // 子账号消费
		subGroup.POST("", accountController.CreateSubAccount)                               // 创建子账号
		subGroup.PUT("/status/:id", accountController.UpdateSubAccountStatus)               // 更新子账号状态
		subGroup.GET("/info/:id", accountController.GetSubAccount)                          // 获取子账号信息
		subGroup.PUT("/:id", accountController.UpdateSubAccount)                            // 更新子账号信息
		subGroup.DELETE("/:id", accountController.DeleteSubAccount)                         // 删除子账号
		subGroup.GET("/:id/consume-records", accountController.GetSubAccountConsumeRecords) // 查询子账号消费明细
	}

}
